package edu.neu.javaweb.controller;

import edu.neu.javaweb.bean.Dept;
import edu.neu.javaweb.bean.Employee;
import edu.neu.javaweb.service.DeptService;
import edu.neu.javaweb.service.EmployeeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet(name = "DeptAddServlet", urlPatterns = {"/pages/dept_add"})
public class DeptAddServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        String name = request.getParameter("name");
        String loc = request.getParameter("loc");

        Dept dept = new Dept(0, name, loc);
        new DeptService().add(dept);
        response.sendRedirect("dept_list");
    }
}
